package com.magicsoft.app.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.boyuan.huijiaoyu.R;
import com.magicsoft.app.entity.CommunityResp;

public class SelectCommunityAdapter extends CTHAdapter<CommunityResp> {

	private int whichCommunitySel = -1;

	public SelectCommunityAdapter(Context context, List<CommunityResp> data,
			int whitch) {
		super(context, data);
		this.whichCommunitySel = whitch;
	}

	@Override
	public int getCount() {

		return data.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		HolderViewStatic viewContent = new HolderViewStatic();

		CommunityResp communityResp = data.get(position);

		if (convertView == null) {

			convertView = mInflater.inflate(
					R.layout.select_community_list_item, null);

			viewContent.textView = (TextView) convertView
					.findViewById(R.id.textview);
			viewContent.iv_tag = (ImageView) convertView
					.findViewById(R.id.iv_tag);

			convertView.setTag(viewContent);

		} else {
			viewContent = (HolderViewStatic) convertView.getTag();
		}

		if (whichCommunitySel == position) {
			viewContent.textView.setSelected(true);
			viewContent.iv_tag.setSelected(true);
		} else {
			viewContent.textView.setSelected(false);
			viewContent.iv_tag.setSelected(false);
		}

		if (communityResp != null) {

			viewContent.textView.setText(communityResp.getName());
		}

		return convertView;

	}

	static class HolderViewStatic {
		TextView textView;
		ImageView iv_tag;
	}

	public void setWhichCommunitySel(int whichCommunitySel) {
		this.whichCommunitySel = whichCommunitySel;
	}
	
}
